<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of "myWiWall".
# Copyright (c) 2007-2008 CRP Henri Tudor and contributors.
# All rights reserved.
#
# "myWiWall" is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
# 
# "myWiWall" is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with "myWiWall"; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# ***** END LICENSE BLOCK *****



// FIXME Maybe should I go in the engine Module ?
/**
 * The Subscribing Module class embeds all actions relevant to the subscription to a widget
 * by a user.
 *
 * @author Laurent Haan <laurent.haan@gmail.com>
 * @author J�r�me Bogaerts <jerome.bogaerts@gmail.com>
 * @package mywiwall.actions
 */
class Subscribing
{
	/**
	 * The subscribe action must be triggered through a GET HTTP Request. It provides an entry
	 * point for a user agent to try to subscribe to a given widget.
	 *
	 */
	public function subscribe()
	{
		$keys = array_keys($_GET);
		$widgetId = $keys[0];
		
		if (!isset($widgetId))
			throw new BadArgumentException(MwwException::CONTROLLER, 'You must provide a widget identifier to subscribe to a widget.');
		
		if (!(Auth :: isAuth())) 
		{
			// forward to the login script.
			DefaultFC::redirection('users/index?ref=subscribe');
			exit;
		}
	
		// No failure for authentication and parameters. We just carry on !
		UserInterface::subscribe(Auth::getUserId(), $widgetId);
		
		DefaultFC::redirection('wall/index');
	}
}
?>